<?php
class job_management extends Zcontroller{
	public function index() {  
		$this->load->model("m_job");
        $data["all_location"]=$this->m_job->get_all_locations();
        $this->load->template("templates/general","jobs/job_view", "Zuka",$data);
    }
    function goto_companies_view(){
    	$this->load->model("m_job");
        $data["all_company"]=$this->m_job->get_company('');
        $this->load->template("templates/general","jobs/companies/companies_view", "Zuka",$data);
    }
    function goto_addnew_company(){
    	$this->load->model("m_job");
    	//$this->load->library("calendar");
        $data =array();
        $data['error_message']='';
        $data['txtname']='';
        $data['txtdesc']='';
        $data['txtaddress']='';
        $data['txtphone']='';
        $data['txtfax']='';
        $data['txtemail']='';
        $data['txtcontact']='';
        $data['txtwebsite']='';
       // $data['all_calendar']= $this->calendar->generate();
        $this->load->template("templates/general","jobs/companies/addnew_company", "Zuka",$data);
    }
    function goto_update_company($id){
    	$this->load->model("m_job");
    	$data =array();
        $data["error_message"] ="";
        $data["company"]=$this->m_job->get_company($id);
        $this->load->template("templates/general","jobs/companies/update_company", "Zuka",$data);
    }
 function save_new_company(){
    	$this->load->model("m_job");
    	$this->load->helper('email');
        $data =array();
        $name=trim($_POST['txtname']);
        $desc=trim($_POST['txtdesc']);
        $address=trim($_POST['txtaddress']);
        $phone=trim($_POST['txtphone']);
        $fax=trim($_POST['txtfax']);
        $email=trim($_POST['txtemail']);
        $contact=trim($_POST['txtcontact']);
        $website=trim($_POST['txtwebsite']);
        $error_message = "";
        $company_name=$this->m_job->get_company_by_name($name);
        if ($name == "") 
        {
        	$error_message = "Company name is required.";	
        }elseif( $company_name<>'')
        {
    		$error_message="Company name already exists.";
    	}else
    	{
        	if ($email!='' && !valid_email($email)){
        		$error_message="Email is not valid.";
        	}
        }
            /* (pretty self-explanatory) */
      $config = array();
      $project_path = str_replace("\\", "/", FCPATH);
      $config['upload_path'] = $project_path.'/images/company_logo/'; /* NB! create this dir! */
      $config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
      $config['max_size']  = '0';
      $config['max_width']  = '0';
      $config['max_height']  = '0';
      /* Load the upload library */
      $this->load->library('upload', $config);
     /* if ( ! $this->upload->do_upload()) {
      	// Failure
      	
      } else {
      	  $upload_data = $this->upload->data();
      	  echo "<pre>"; var_dump($upload_data);echo "</pre>";
      } */
      
      /* Create the config for image library */
      /* (pretty self-explanatory) */
      $configThumb = array();
      $configThumb['image_library'] = 'gd2';
      $configThumb['source_image'] = '';
      $configThumb['create_thumb'] = TRUE;
      $configThumb['maintain_ratio'] = TRUE;
      $configThumb['width'] = 140;
      $configThumb['height'] = 210;
      /* Load the image library */
      $this->load->library('image_lib');
        
        if ($error_message != "") {
        	$data['txtname']=$name;
        	$data['txtdesc']=$desc;
	        $data['txtaddress']=$address;
	        $data['txtphone']=$phone;
	        $data['txtfax']=$fax;
	        $data['txtemail']=$email;
	        $data['txtcontact']=$contact;
	        $data['txtwebsite']=$website;
        	$data["error_message"] = $error_message;
        	$this->load->template("templates/general","jobs/companies/addnew_company", "Zuka",$data);
        	return;
        }
        
        $this->m_job->insert_new_company($name,
							        	$desc,
							        	$address,
							        	$phone,
							        	$fax,
							        	$email,
							        	$contact,
							        	$website);
		$logotype=$_FILES['imagefile']['type'];
 		if($logotype <> ''){
 			$ext = $this->findexts ($_FILES['imagefile']['name']) ;
          	$comid=$this->m_job->get_company_maxid();
	   		$nname=$comid['com_id'].".";
       		$ext = $this->findexts ($_FILES['imagefile']['name']) ;
       		$logoname=$nname.$ext;
       		$target=$project_path.'/images/company_logo/'.$logoname;
       		move_uploaded_file($_FILES['imagefile']['tmp_name'],$target);
       		$this->m_job->upload_logo($logoname,$logotype,$comid['com_id']);
       		
        }
		redirect(site_url("job_management/goto_companies_view"));
    }
	function findexts($filename) {
	if (!empty($filename)) {
		$filename = strtolower($filename);
		$extArray = explode(".", $filename);
		$exts="";
		foreach ($extArray as $exten):
			$exts=$exten;
		endforeach;
		return $exts;
			//echo "<pre>"; var_dump($exts);echo "</pre>";
	}else{
		return FALSE;
	}
}
	function showcompanylogo($com_id){
           $this->load->model("m_advertisment");
           $result=$this->m_job->get_company($com_id);
           $image_content=$result[0]->com_logo;
           header("Content-type:".$result[0]->com_logo_type);
           print $image_content;
       }
       
  function delete_img_from_folder($image_name){
  	 $project_path = str_replace("\\", "/", FCPATH);
     $image_path = $project_path.'/images/company_logo/'.$image_name;
    unlink($image_path);
  }

  function DeleteAds($infoid){
      $this->load->model("m_advertisment");
      $data['allimages']=$this->m_advertisment->SelectProductWhereID($infoid);
      $this->delete_img_from_folder($data['allimages'][0]->image_file1);
      $this->delete_img_from_folder($data['allimages'][0]->image_file2);
      $this->delete_img_from_folder($data['allimages'][0]->image_file3);
      $this->delete_img_from_folder($data['allimages'][0]->image_file4);
      $this->m_advertisment->DeleteProduct($infoid);
      redirect(base_url()."index.php/c_advertisment/ViewAd_UserID");
  }
    function save_update_company($comid){
    	$this->load->model("m_job");
    	$this->load->helper('email');
        $data =array();
        $name=trim($_POST['txtname']);
        $desc=trim($_POST['txtdesc']);
        $address=trim($_POST['txtaddress']);
        $phone=trim($_POST['txtphone']);
        $fax=trim($_POST['txtfax']);
        $email=trim($_POST['txtemail']);
        $contact=trim($_POST['txtcontact']);
        $website=trim($_POST['txtwebsite']);
        $error_message = "";
        $company_name = $this->m_job->get_company_by_name($name);
        if ($name == "") {
        	$error_message = "Company name is required.";	
        }elseif ($email!='' && !valid_email($email)){
        	$error_message="Email is not valid.";
        }else{
        	if($company_name['com_name']<>''){
        		if($company_name['com_id']!= $comid){
        			$error_message="Company name already exists.";
        		}
        	}
        }
        if ($error_message != "") {
        	$data["error_message"] = $error_message;
        	$data["company"]=$this->m_job->get_company($comid);
        	$this->load->template("templates/general","jobs/companies/update_company", "Zuka",$data);
        	return;
        }
        $this->m_job->update_company($name,
							         $desc,
							         $address,
							         $phone,
							         $fax,
							         $email,
							         $contact,
							         $website,
							         $comid);
     
      $logotype=$_FILES['imagefile']['type'];
      $chkdeletelogo=$_POST['chkdelete'];
      if($chkdeletelogo==''){  //not delete image
         if($logotype<>''){     //when user choose another image
         	if($company_name['com_logo']<>''){//when has old logo
         		//delet old image 1
             	$this->delete_img_from_folder($company_name['com_logo']);
         	}
             //add new image
             $nlogoname=$comid.".";
             $ext = $this->findexts ($_FILES['imagefile']['name']) ;
             $newlogoname=$nlogoname.$ext;
           	 $project_path = str_replace("\\", "/", FCPATH);
     		 $target = $project_path.'/images/company_logo/'.$newlogoname;
             move_uploaded_file($_FILES['imagefile']['tmp_name'],$target);

             $this->m_job->update_logo($newlogoname,$logotype,$comid);
          }
      }else{   //when user check on checkbox to delete image
      		if($company_name['com_logo']<>''){//when has old logo
         		//delet old image 1
             	$this->delete_img_from_folder($company_name['com_logo']);
         	}
            if($logotype<>''){ //check to delete n choose new image
                 //add new image
                 $nlogoname=$comid.".";
           		 $ext = $this->findexts ($_FILES['imagefile']['name']) ;
           		$newlogoname=$nlogoname.$ext;
           		$project_path = str_replace("\\", "/", FCPATH);
     			$target = $project_path.'/images/company_logo/'.$newlogoname;
           		move_uploaded_file($_FILES['imagefile']['tmp_name'],$target);

               $this->m_job->update_logo($newlogoname,$logotype,$comid);

            }else{  //check on checkbox to delete image without choosing the new one
                $this->m_job->update_logo('','',$comid);
            }
      }
		redirect(site_url("job_management/goto_companies_view"));
    }
    function delete_company($comid,$logoname){
    	$this->load->model("m_job");
    	 $data =array();
    	$data['announdata']=$this->m_job->get_announ_by_comid($comid);
    	foreach ($data['announdata']->result() as $announ)://get all announcement of company
    		$data['titledata']=$this->m_job->get_title_by_announ($announ->announ_id);
    		foreach ($data['titledata']->result() as $title)://get all title of announcement
    			$this->m_job->delete_titleloc_by_titleid($title->title_id);//table: titles_locations
    			$this->m_job->delete_requirement_by_titleid($title->title_id);//table: requirement
    			$this->m_job->delete_duty_by_titleid($title->title_id);//table: duty
    			$this->m_job->delete_titlecate_by_titleid($title->title_id);//table: titles_categories
    		endforeach;
    		$this->m_job->delete_title_annouid($announ->announ_id);//table: title
    		$this->m_job->delete_announ($announ->announ_id);//table: announcement
    	endforeach;
    	$this->delete_img_from_folder($logoname);
    	$this->m_job->delete_company($comid);
    	redirect(site_url("job_management/goto_companies_view"));
    }
    
    //========== announce ===========
    function goto_announce_view(){
    	$this->load->model("m_job");
    	 $data =array();
    	$data["all_company"]=$this->m_job->get_company('');
        $data["all_announce"]=$this->m_job->get_allannoun();
        $this->load->template("templates/general","jobs/job_announcements/announ_view", "Zuka",$data);
    }
    function goto_addnew_announ(){
    	$this->load->model("m_job");
    	$data =array();
        $data['error_message']='';
        $data['cbocompany']='';
        $data['datepost']='';
        $data['dateclose']='';
        $data['txtnote']='';
    	$data["all_company"]=$this->m_job->get_company('');
    	$this->load->template("templates/general","jobs/job_announcements/addnew_announ", "Zuka",$data);
    }
   
    function save_addnew_announ(){
    	$this->load->model("m_job");
    	 $data =array();
        $company=trim($_POST['cbocompany']);
        $postdate=trim($_POST['datepost']);
        $closedate=trim($_POST['dateclose']);
        $notice=trim($_POST['txtnote']);
        $error_message = "";
        if ($postdate==""){
        	$error_message = "Post date is required.";	
        }
        if ($closedate==""){
        	$error_message = "Closing date is required.";	
        }
        if ($notice==""){
        		$error_message = "Notice is required.";	
        }
        if ($error_message != "") {
        	$data["cbocompany"]=$company;
        	$data["postdate"]=$postdate;
        	$data["closedate"]=$closedate;
        	$data["error_message"] = $error_message;
        	$data["txtnotice"]=$notice;
        	$this->load->template("templates/general","jobs/job_announcements/addnew_announ", "Zuka",$data);
        	return;
        }
        $this->m_job->save_new_announ($postdate,$closedate,$notice,$company);
		redirect(site_url("job_management/goto_announce_view"));
    }
    function goto_update_announ($comid,$announid){
    	$this->load->model("m_job");
    	 $data =array();
    	$data["error_message"] ="";
        $data["all_company"]=$this->m_job->get_company('');
        $data["companyname"]=$this->m_job->get_company($comid);
        $data["announce"]=$this->m_job->get_announ_by_id($announid);
        $this->load->template("templates/general","jobs/job_announcements/update_announ", "Zuka",$data);
    }
    function save_update_announ($announid){
    	$this->load->model("m_job");
    	$data =array();
        $company=trim($_POST['cbocompany']);
        $postdate=trim($_POST['datepost']);
        $closedate=trim($_POST['dateclose']);
        $notice=trim($_POST['txtnote']);
        $error_message = "";
        if ($postdate==""){
        	$error_message = "Post date is required.";	
        }
        if ($closedate==""){
        	$error_message = "Closing date is required.";	
        }
        if ($notice==""){
        	$error_message = "Notice is required.";	
        }
        if ($error_message != "") {
        	$data["error_message"] = $error_message;
        	$data["all_company"]=$this->m_job->get_company('');
        	$data["announce"]=$this->m_job->get_announ_by_id($id);
        	$this->load->template("templates/general","jobs/job_announcements/update_announ", "Zuka",$data);
        	return;
        }
        $this->m_job->save_update_announ($postdate,$closedate,$notice,$company,$announid);
		redirect(site_url("job_management/goto_announce_view"));
    }
    function delete_announ($announid){
    	$this->load->model("m_job");
    	 $data =array();
    	$data['titledata']=$this->m_job->get_title_by_announ($announid);
    	foreach ($data['titledata']->result() as $title)://get all title of announcement
    		$this->m_job->delete_titleloc_by_titleid($title->title_id);//table: titles_locations
    		$this->m_job->delete_requirement_by_titleid($title->title_id);//table: requirement
    		$this->m_job->delete_duty_by_titleid($title->title_id);//table: duty
    		$this->m_job->delete_titlecate_by_titleid($title->title_id);//table: titles_categories
    	endforeach;
    	$this->m_job->delete_title_annouid($announid);//table: title
    	$this->m_job->delete_announ($announid);//table: announcement
    	
		redirect(site_url("job_management/goto_announce_view"));
    }
    function search_result(){
    	$this->load->model("m_job");
    	 $data =array();
    	$comid=trim($_POST['cbocompany']);
    	$data["com_id"]=$comid;
    	$data["all_company"]=$this->m_job->get_company('');
        $data["com_announce"]=$this->m_job->get_announ_by_comid($comid);
        $this->load->template("templates/general","jobs/job_announcements/search_result", "Zuka",$data);
    }
    //===================== title =============================
    function goto_title_view($comid,$announid){
    	$this->load->model("m_job");
    	 $data =array();
    	$data["company"]=$this->m_job->get_company($comid);
    	$data["announceid"]=$announid;
    	$data["all_title"]=$this->m_job->get_title_by_announ($announid);
    	$this->load->template("templates/general","jobs/job_announcements/title_view", "Zuka",$data);
    }
    function goto_addnew_title($comid,$announid){
    	$this->load->model("m_job");
    	$data =array();
        $data['error_message']='';
        $data['anid']=$announid;
        $company=$this->m_job->get_company($comid);
        $data['txtcompany']=$company['com_name'];
        $data['comid']=$comid;
        $data['txtdesc']='';
    	$this->load->template("templates/general","jobs/job_announcements/addnew_title", "Zuka",$data);
    }
    function save_addnew_title($comid,$announid){
    	$this->load->model("m_job");
    	$data =array();
    	$description=trim($_POST['txtdesc']);
    	$comname=trim($_POST['txtcompany']);
        if ($description==""){
        	$data["error_message"] = "Description is required.";
        	$data['txtannounid']=$announid;
        	$data['txtcompany']=$comname;
        	$data['txtdesc']=$description;
    		$this->load->template("templates/general","jobs/job_announcements/addnew_title", "Zuka",$data);	
    		return ;
        }
        $this->m_job->insert_new_title($description,$announid);
        redirect(site_url("job_management/goto_title_view/".$comid."/".$announid));        
    }
    function goto_update_title($titleid,$comid){//goto_title_view($comid,$announid){
    	$this->load->model("m_job");
    	$data =array();
        $data['error_message']='';
        $company=$this->m_job->get_company($comid);
        $data['companyname']=$company['com_name'];
        $data['companyid']=$comid;
        $data['announ']=$this->m_job->get_announ_by_titleid($titleid);
        $data['titles']=$this->m_job->get_title_by_id($titleid);
    	$this->load->template("templates/general","jobs/job_announcements/update_title", "Zuka",$data);
    }
    function save_update_title($comid,$announid){
    	$this->load->model("m_job");
    	$titleid=trim($_POST['txttitleid']);
    	$titledesc=trim($_POST['txttitledesc']);
    	$data=array();
    	if($titledesc==''){
    		$data['error_message']='Description is required.';
    		$company=$this->m_job->get_company($comid);
	        $data['companyname']=$company['com_name'];
	        $data['companyid']=$comid;
	        $data['announ']=$this->m_job->get_announ_by_comid($comid);
	        $data['titles']=$this->m_job->get_title_by_id($titleid);
	    	$this->load->template("templates/general","jobs/job_announcements/update_title", "Zuka",$data);
    		return ;
    	}
    	$this->m_job->save_update_title($titledesc,$announid,$titleid);//save_update_title($desc,$annouid,$titleid)
        redirect(site_url("job_management/goto_title_view/".$comid."/".$announid));   
    }
    function delete_title($titleid,$comid){
    	$this->load->model("m_job");
    	$announ=$this->m_job->get_announ_by_titleid($titleid);
    	$this->m_job->delete_titleloc_by_titleid($titleid);//delete in table title_location
    	$this->m_job->delete_titlecate_by_titleid($titleid);//delete in table title_category
    	$this->m_job->delete_duty_by_titleid($titleid);//delete in table duties
    	$this->m_job->delete_requirement_by_titleid($titleid);//delete in table requirement
    	$this->m_job->delete_title($titleid);
		redirect(site_url("job_management/goto_title_view/".$comid."/".$announ['announ_id'])); 
    }
    
    //=================== Job Category ======================
    function goto_category_view(){
    	$this->load->model("m_job");
    	$data['all_cate']=$this->m_job->get_all_category();
    	$this->load->template("templates/general","jobs/job_categories/category_view", "Zuka",$data);
    }
    
    function goto_addnew_category(){
    	$this->load->model("m_job");
    	$data =array();
        $data['error_message']='';
        $data['txtcatedesc']='';
    	$this->load->template("templates/general","jobs/job_categories/addnew_category", "Zuka",$data);
    }
    function save_addnew_category(){
    	$this->load->model("m_job");
    	$catedesc=trim($_POST['txtcatedesc']);
    	 $data =array();
    	$error_message='';
    	$category= $this->m_job->get_category_by_name($catedesc);
        if($catedesc==""){
        	$error_message="Description is required. ";
        }else{//check if category desc exists
        	if($category!=''){
        		$error_message="Description already exists.";
        	}
        }
        if($error_message!=''){
        	$data['error_message']=$error_message;
        	$data["txtcatedesc"]=$catedesc;
        	$this->load->template("templates/general","jobs/job_categories/addnew_category", "Zuka",$data);
        	return;
        }
        $this->m_job->insert_new_category($catedesc);
		redirect(site_url("job_management/goto_category_view"));
    }
    function goto_update_category($cateid){
    	$this->load->model("m_job");
    	$data =array();
        $data['error_message']='';
    	$data['cate']=$this->m_job->get_category_by_id($cateid);
    	$this->load->template("templates/general","jobs/job_categories/update_category", "Zuka",$data);
    }
    function save_update_category(){
    	$this->load->model("m_job");
    	$cateid=trim($_POST['txtcateid']);
    	$catedesc=trim($_POST['txtcatedesc']);
    	$data =array();
        $error_message='';
        $category= $this->m_job->iscategoryexist($cateid,$catedesc);
        if($catedesc==""){
        	$error_message="Description is required.";
        }else {
	       	if($category!=''){
	       		$error_message="Description already exists.";
	       	}
        }
        if($error_message!=''){
        	$data['error_message']=$error_message;
        	$data['cate']=$this->m_job->get_category_by_id($cateid);
    		$this->load->template("templates/general","jobs/job_categories/update_category", "Zuka",$data);
    		return ;
        }
        $this->m_job->save_update_category($catedesc,$cateid);
		redirect(site_url("job_management/goto_category_view"));
    }
    function delete_category($cateid){
    	$this->load->model("m_job");
    	$this->m_job->delete_category($cateid);
		redirect(site_url("job_management/goto_category_view"));
    }
    
    //================== Duty ============================
     function goto_duty_view($titleid){
    	$this->load->model("m_job");
    	 $data =array();
    	$data['titledata']=$this->m_job->get_title_by_id($titleid);
    	$data['all_duties']=$this->m_job->get_number_duty($titleid);
    	$data['announ']=$this->m_job->get_announ_by_titleid($titleid);
    	$data['company']=$this->m_job->get_company_by_announid($data['announ']['announ_id']);
    	$this->load->template("templates/general","jobs/job_announcements/duty/duty_view", "Zuka",$data);
    }
    function goto_addnew_duty($titleid){
    	$this->load->model("m_job");
    	 $data =array();
    	$data['error_message']='';
    	$data['txtdutydesc']='';
    	$data['titledata']=$this->m_job->get_title_by_id($titleid);
    	$this->load->template("templates/general","jobs/job_announcements/duty/addnew_duty", "Zuka",$data);
    }
    function save_addnew_duty($titleid){
    	$this->load->model("m_job");
    	 $data =array();
    	$dutydesc=trim($_POST['txtdutydesc']);
    	if($dutydesc==''){
    		$data['error_message']='Duty description is required.';
    		$data['txtdutydesc']=$dutydesc;
	    	$data['titledata']=$this->m_job->get_title_by_id($titleid);
	    	$data['all_duty']=$this->m_job->get_number_duty($titleid);
	    	$this->load->template("templates/general","jobs/job_announcements/duty/addnew_duty", "Zuka",$data);
	    	return ;
    	}
    	$this->m_job->insert_new_duty($dutydesc,$titleid);
    	redirect(site_url("job_management/goto_duty_view/$titleid"));
    }
    function goto_update_duty($dutyid,$titleid){
    	$this->load->model("m_job");
    	 $data =array();
    	$data['error_message']='';
    	$data['duty']=$this->m_job->get_duty_by_id($dutyid);
    	$data['titledata']=$this->m_job->get_title_by_id($titleid);
    	$this->load->template("templates/general","jobs/job_announcements/duty/update_duty", "Zuka",$data);
    }
    function save_update_duty($titleid){
    	$this->load->model("m_job");
    	 $data =array();
    	$dutyid=trim($_POST['txtdutyid']);
    	$dutydesc=trim($_POST['txtdutydesc']);
    	if($dutydesc==''){
    		$data['error_message']='Duty description is required.';
    		$data['duty']=$this->m_job->get_duty_by_id($dutyid);
	    	$data['titledata']=$this->m_job->get_title_by_id($titleid);
	    	$this->load->template("templates/general","jobs/job_announcements/duty/update_duty", "Zuka",$data);
	    	return ;
    	}
    	$this->m_job->save_update_duty($dutyid,$dutydesc,$titleid);
    	redirect(site_url("job_management/goto_duty_view/$titleid"));
    }
    function delete_duty($dutyid,$titleid){
    	$this->load->model("m_job");
    	$this->m_job->delete_duty($dutyid);
		redirect(site_url("job_management/goto_duty_view/$titleid"));
    }
    //================== Requirement =====================
	function goto_requirement_view($titleid){
    	$this->load->model("m_job");
    	 $data =array();
    	$data['titledata']=$this->m_job->get_title_by_id($titleid);
    	$data['all_requirement']=$this->m_job->get_number_requirement($titleid);
    	$data['announ']=$this->m_job->get_announ_by_titleid($titleid);
    	$data['company']=$this->m_job->get_company_by_announid($data['announ']['announ_id']);
    	$this->load->template("templates/general","jobs/job_announcements/requirement/requirement_view", "Zuka",$data);
    }
	function goto_addnew_requirement($titleid){
    	$this->load->model("m_job");
    	 $data =array();
    	$data['error_message']='';
    	$data['txtreqdesc']='';
    	$data['titledata']=$this->m_job->get_title_by_id($titleid);
    	$this->load->template("templates/general","jobs/job_announcements/requirement/addnew_requirement", "Zuka",$data);
    }
    function save_addnew_requirement($titleid){
    	$this->load->model("m_job");
    	$reqid=trim($_POST['txtreqid']);
    	$reqdesc=trim($_POST['txtreqdesc']);
    	 $data =array();
    	if($reqdesc==''){
    		$data['error_message']='Requirement description is required.';
    		$data['txtreqdesc']=$reqdesc;
	    	$data['titledata']=$this->m_job->get_title_by_id($titleid);
	    	$this->load->template("templates/general","jobs/job_announcements/requirement/update_requirement", "Zuka",$data);
	    	return ;
    	}
    	$this->m_job->insert_new_requirement($reqdesc,$titleid);
    	redirect(site_url("job_management/goto_requirement_view/$titleid"));
    }
    function goto_update_requirement($reqid,$titleid){
    	$this->load->model("m_job");
    	 $data =array();
    	$data['error_message']='';
    	$data['Requirement']=$this->m_job->get_requirement_by_id($reqid);
    	$data['titledata']=$this->m_job->get_title_by_id($titleid);
    	$this->load->template("templates/general","jobs/job_announcements/requirement/update_requirement", "Zuka",$data);
    }
    function save_update_requirement($titleid){
    	$this->load->model("m_job");
    	 $data =array();
    	$reqid=trim($_POST['txtreqid']);
    	$reqdesc=trim($_POST['txtreqdesc']);
    	if($reqdesc==''){
    		$data['error_message']='Requirement description is required.';
    		$data['Requirement']=$this->m_job->get_requirement_by_id($reqid);
	    	$data['titledata']=$this->m_job->get_title_by_id($titleid);
	    	$this->load->template("templates/general","jobs/job_announcements/requirement/update_requirement", "Zuka",$data);
	    	return ;
    	}
    	$this->m_job->save_update_requirement($reqid,$reqdesc,$titleid);
    	redirect(site_url("job_management/goto_requirement_view/$titleid"));
    }
    function delete_requirement($reqid,$titleid){
    	$this->load->model("m_job");
    	$this->m_job->delete_requirement($reqid);
		redirect(site_url("job_management/goto_requirement_view/$titleid"));
    }
    
    //==================== titles_categories =================
	function goto_view_category_titleid($titleid){
    	$this->load->model("m_job");
    	 $data =array();
    	$data['title']=$this->m_job->get_title_by_id($titleid);
    	$data['all_cate']=$this->m_job->get_number_category($titleid);
    	$data['announ']=$this->m_job->get_announ_by_titleid($titleid);
    	$data['company']=$this->m_job->get_company_by_announid($data['announ']['announ_id']);
    	$this->load->template("templates/general","jobs/job_announcements/title_category/titlecate_view", "Zuka",$data);
    }
    function goto_addnew_titlecate($titleid){
    	$this->load->model("m_job");
    	 $data =array();
    	$data['error_message']='';
    	$data['titledata']=$this->m_job->get_title_by_id($titleid);
    	$data['all_category']=$this->m_job->get_all_category();
    	$this->load->template("templates/general","jobs/job_announcements/title_category/addnew_titlecate", "Zuka",$data);
    }
    function save_addnew_titlecate($titleid){
    	$this->load->model("m_job");
    	 $data =array();
    	$cateid=trim($_POST['cbocategory']);
    	$istitlecateexist=$this->m_job->istitlecategoryexist($titleid,$cateid);
    	if($istitlecateexist!=''){
    		$data['error_message']="Category already exists.";
    		$data['titledata']=$this->m_job->get_title_by_id($titleid);
	    	$data['all_category']=$this->m_job->get_all_category();
	    	$this->load->template("templates/general","jobs/job_announcements/title_category/addnew_titlecate", "Zuka",$data);
    		return ;
    	}
    	$this->m_job->save_addnew_titlecate($titleid,$cateid);
    	redirect(site_url("job_management/goto_view_category_titleid/$titleid"));
    }
    function delete_titlecate($cateid,$titleid){
    	$this->load->model("m_job");
    	$this->m_job->delete_titlecate_by_cateid($cateid);
    	redirect(site_url("job_management/goto_view_category_titleid/$titleid"));
    }
    
    //================== titles_locations ==========================
	function goto_view_location_titleid($titleid){
    	$this->load->model("m_job");
    	 $data =array();
    	$data['title']=$this->m_job->get_title_by_id($titleid);
    	$data['all_location']=$this->m_job->get_number_location($titleid);
    	$data['announ']=$this->m_job->get_announ_by_titleid($titleid);
    	$data['company']=$this->m_job->get_company_by_announid($data['announ']['announ_id']);
    	$this->load->template("templates/general","jobs/job_announcements/title_location/titleloc_view", "Zuka",$data);
    }
    function goto_addnew_titleloc($titleid){
    	$this->load->model("m_job");
    	 $data =array();
    	$data['error_message']='';
    	$data['titledata']=$this->m_job->get_title_by_id($titleid);
    	$data['all_location']=$this->m_job->get_all_locations();
    	$this->load->template("templates/general","jobs/job_announcements/title_location/addnew_titleloc", "Zuka",$data);
    }
    function save_addnew_titleloc($titleid){
    	$this->load->model("m_job");
    	 $data =array();
    	$locid=trim($_POST['cbolocation']);
    	$istitlelocexist=$this->m_job->istitlelocationexist($titleid,$locid);
    	if($istitlelocexist!=''){
    		$data['error_message']="Location already exists.";
    		$data['titledata']=$this->m_job->get_title_by_id($titleid);
	    	$data['all_location']=$this->m_job->get_all_locations();
	    	$this->load->template("templates/general","jobs/job_announcements/title_location/addnew_titleloc", "Zuka",$data);
    		return ;
    	}
    	$this->m_job->save_addnew_titleloc($titleid,$locid);
    	redirect(site_url("job_management/goto_view_location_titleid/$titleid"));
    }
    function delete_titleloc($locid,$titleid){
    	$this->load->model("m_job");
    	$this->m_job->delete_titleloc_by_locid($locid);
    	redirect(site_url("job_management/goto_view_location_titleid/$titleid"));
    }
    
}
?>